package com.designpatterns.command.command.ceiling;

import com.designpatterns.command.command.Command;
import com.designpatterns.command.entity.CeilingFan;

public class CeilingFanMediumCommand implements Command {

    CeilingFan ceilingFan;
    int prevSpeed;

    public CeilingFanMediumCommand(CeilingFan ceilingFan){
        this.ceilingFan = ceilingFan;
    }
    @Override
    public void excute() {
        prevSpeed = ceilingFan.getSpeed();
        ceilingFan.medium();
    }

    @Override
    public void undo() {
        skip(prevSpeed, ceilingFan);
    }

    static void skip(int prevSpeed, CeilingFan ceilingFan) {
        if (prevSpeed == CeilingFan.HIGH){
            ceilingFan.high();
        }else if(prevSpeed == CeilingFan.MEDIUM){
            ceilingFan.medium();
        }else if(prevSpeed == CeilingFan.LOW) {
            ceilingFan.low();
        }else if(prevSpeed == CeilingFan.OFF) {
            ceilingFan.off();
        }
    }
}
